Debugging is an essential part of developing with BRX. This guide covers techniques and best practices for identifying and resolving issues in your BRX workflows.
To debug output issues, examine the results of BRK execution:
Copy
Ask AI
const result = await brx.run(myBrk);// Log the full resultconsole.log('BRK Result:', JSON.stringify(result, null, 2));// Check specific output propertiesif (!result[0].brxRes.output) { console.error('Missing output in result');}
To debug prompt issues, you can inspect the prompts that are sent to the LLM:
Copy
Ask AI
// Log the prompt templateconsole.log('Prompt Template:', myBrk.brxQuery.userSchemaInteract.schemas.get('main_brx_entry_schema').schemaFields.get('prompt').fieldValue);// Log the rendered prompt (with variables replaced)// Note: This requires access to the internal BRX engine, which may not be directly accessible
You can test prompts independently of BRX to isolate issues:
Copy
Ask AI
// Test a prompt with a direct API call to an LLMconst testPrompt = async (prompt) => { // Use your preferred LLM API client const response = await openai.createCompletion({ model: 'text-davinci-003', prompt, max_tokens: 500 }); return response.choices[0].text;};// Test the prompt with sample inputsconst samplePrompt = `Generate a product description for the following:Product Name: Ultra Comfort Ergonomic ChairProduct Category: Office FurnitureKey Features: Adjustable height, lumbar support, breathable mesh, 360-degree swivelTarget Audience: Office workers, remote professionals`;const result = await testPrompt(samplePrompt);console.log('Test Result:', result);
Test each BRK in the dependency chain individually:
Copy
Ask AI
// Test each BRK in isolationconst testDependencyChain = async () => { // Test the first BRK const extractBrkSchema = await brx.get('extract-brk-id'); const extractBrk = new BRK(extractBrkSchema); extractBrk.input['text'] = 'Sample text to extract data from'; const extractResult = await brx.run(extractBrk); console.log('Extract Result:', extractResult[0].brxRes.output); // Test the second BRK with the output of the first const analyzeBrkSchema = await brx.get('analyze-brk-id'); const analyzeBrk = new BRK(analyzeBrkSchema); analyzeBrk.input['data'] = extractResult[0].brxRes.output; const analyzeResult = await brx.run(analyzeBrk); console.log('Analyze Result:', analyzeResult[0].brxRes.output); // Continue for each BRK in the chain};testDependencyChain();
For complex workflows, you can mock dependencies to isolate issues:
Copy
Ask AI
// Mock a dependency BRKconst mockDependency = async (dependencyBrkId, mockOutput) => { // Create a mock BRK with the same ID but simplified behavior const mockBrkRequest = { modifyBrxMode: 'CREATE', brx: { brxId: `mock-${dependencyBrkId}`, brxName: `Mock ${dependencyBrkId}`, description: 'A mock BRK for testing', prompt: { prompt: new Map([ ['main', `Return the following mock output: ${mockOutput}`] ]) }, processParams: { processType: 0 }, dependantBrxIds: new Map([ ['main_brx_entry_schema', `mock-${dependencyBrkId}`] ]) }, schema: { schemaFields: new Map([]), brxName: `Mock ${dependencyBrkId}`, brxId: `mock-${dependencyBrkId}` } }; const result = await brx.create(mockBrkRequest); console.log(`Mock BRK created for ${dependencyBrkId}:`, result); return result;};// Create a mock dependencyawait mockDependency('data-extraction-brk', '{"extracted_data": "This is mock extracted data"}');// Update the main BRK to use the mock dependency// This would require modifying the dependantBrxIds map
Implement monitoring for production BRX applications:
Monitor API usage and rate limits
Track execution times and performance
Set up alerts for errors and failures
Analyze usage patterns to identify optimization opportunities
By following these debugging techniques and best practices, you can effectively identify and resolve issues in your BRX workflows, leading to more reliable and efficient applications.